/*
  Meant for use in conjunction with a dictionary for use with xml files
*/
#ifndef LIST_H
#define LIST_H
#include <stdio.h>
#include <stdlib.h>


#include "dict.h"
/*
 * List types are the same as dict types, please use those!
 */

/*TODO: Incorporating lists into xmldict
 *  	Basically, if you find yourself needing to insert an item into
 * 		a dictionary that already exists you need to form a list!
 */

struct list 
{
  int ref;
  int size;
  struct list_item *items;
};

struct list_item
{
  void *value;
  int type;
  int free;
  struct list_item *next;
};

/* Iterator access to an existing list: */
typedef struct list_item lstiter;

lstiter *list_start_iter(struct list *lst);
//Pre:  lst is a valid list
//Post:  Returns an iter

lstiter *list_iter_next(lstiter *iter);
//Pre:  lstiter is a valid iter
//Post:  returns the next item, or NULL

void *list_iter_get(lstiter *iter);
//Pre:  lstiter is a valid iter
//Post:  Returns the item for lstiter.

int list_iter_get_type(lstiter *iter);
//Pre:
//Post:  returns the type for the item associated with iter.



/* making a new list */
struct list *list_new();
//Pre:
//Post:  Create a new list structure

struct list *list_from_dict(struct dict *d);
//Pre: d is a valid dict
//Post:  returns a new list with d's data.
/*Warning:
 * Due to the radically different natures of dicts and lists this may not always work
 * All this function really does is grab the first value from dict and make it a list
 * because this is the only time their functionality really collides, is 1 value.
 */


void list_add(struct list *l, void *val);
//Pre: l has been made with list_new
//Post:  adds val to the list.


void list_rm(struct list *l, void *val);
//Pre:
//Post:  any value with address val is removed from the list.

void list_free_able(struct list *l, int free);
//Pre:  an item is on the list
//Post:  the top item (last added) will be freed if free!=0 when needed.

void list_type(struct list *l, int type);
//Pre: an item is on the list.
//Post:  The top item (last added) will be set to type
//       See dict.h for types
//See dict.h for types.

void list_print(struct list *l);
//Pre: l is a valid list
//Post:  prints l to the screen, recursively if necessary

void list_free(struct list *l);
//Pre: l was alloced with list_new
//Post:  object is destroyed

int list_size(struct list *l);
//Pre:
//Post:  returns the number of items in list.

void list_ref(struct list *l);
void list_unref(struct list *l);
//it's preferred to use these...

#endif
